package Thread.DeadLock;

public class DeadLockTest {
    public static void main(String[] args) {
        Object projectLock = new Object();
        Object songLock = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (projectLock) {
                System.out.println("舒服了，我开始写项目");
                synchronized (songLock) {
                    System.out.println("老师先唱个曲儿，我再去写项目");
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        },"学生");
        Thread t2 = new Thread(() -> {
            synchronized (projectLock) {
                System.out.println("大家先把项目写完，我再唱个曲儿~~");
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (songLock) {
                    System.out.println("大家写完项目了，我给大家来一首***");
                }
            }
        },"老师");
        t1.start();
        t2.start();
    }
}
